<script>
	import {
		mapMutations
	} from "vuex"
	export default {
		methods: {
			getCode() {
				return new Promise(resolve => {
					uni.login({
						provider: 'weixin',
						success: ({
							code
						}) => {
							resolve(code)
						}
					})
				})
			},
			async handleLogin() {
				// #ifdef MP-WEIXIN
				let wxCode = await this.getCode()
				let query = {
					code: wxCode
				}
				let {
					code,
					data
				} = await this.$h.api.userModel.wxLogin(query)
				
				if (code === 1) {
					this.SET_TOKEN(data.token)
					let {
						data:userInfo
					} = await this.waitingLoading(this.$h.api.userModel.getMyPage)()
					if (this.$h.utils.isNotEmptyObj(userInfo)) {
						this.SET_USERINFO(userInfo)
					}
				}
				// #endif
				// #ifdef H5
				this.$h.router.push({
					path:"/login/login"
				})
				// #endif
				
			},
			...mapMutations('app', ['SET_CUSTOMBAR', 'SET_CUSTOM', 'SET_STATUSBAR','SET_SYSTEM']),
			...mapMutations('user', ['SET_TOKEN','SET_USERINFO'])
		},
		onLaunch: function(options) {
			console.log('App Launch')
			this.SET_TOKEN('') //每次打开小程序先清空token，防止过期
			this.SET_SYSTEM(uni.getSystemInfoSync().platform)
			uni.getSystemInfo({
				success: e => {
					// #ifdef MP-WEIXIN
					// this.$GlobalData.StatusBar = e.statusBarHeight;//获取头部状态栏bar的高度（显示信号电池栏的高度）
					let custom = uni.getMenuButtonBoundingClientRect(); //胶囊按钮，目的是为了与胶囊按钮保持水平位置一致
					this.SET_CUSTOMBAR(custom.bottom + custom.top - e.statusBarHeight + 4)
					this.SET_STATUSBAR(e.statusBarHeight)
					this.SET_CUSTOM(custom)
					// #endif
				},
				fail: e => {
					console.log('err' + e)
				}
			})
			this.handleLogin()
		},
		onLoad(options){
			console.log(options)
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import 'colorui/main.css';
	@import 'colorui/icon.css';
	@import 'colorui/animation.css';

	body {
		background-color: $bgColor;
		font-family: 'PingFangSC-Medium''PingFang SC';
		color: $textColor;
	}

	.hidden2,
	.hidden3,
	.hidden4,
	.hidden5 {
		display: -webkit-box;
		/* autoprefixer:off */
		-webkit-box-orient: vertical;
		overflow: hidden
	}

	.hidden2 {
		-webkit-line-clamp: 2
	}

	.hidden3 {
		-webkit-line-clamp: 3
	}

	.hidden4 {
		-webkit-line-clamp: 4
	}

	.hidden5 {
		-webkit-line-clamp: 5
	}

	.text-666 {
		color: #666666;
	}

	.text-999 {
		color: #999999;
	}

	.img-box {
		overflow: hidden;
		border: 1rpx solid rgba(0, 0, 0, .03);
	}

	.flex-shrink {
		flex-shrink: 0;
	}

	/* 关注的按钮 开始 */
	.cu-btn.custom-btn-follow {
		width: 120rpx;
		height: 50rpx;
		font-size: 20rpx;
		color: $textColor;
		padding: 0;
		font-weight: 500;

		.cuIcon-add {
			font-size: 24rpx;
			color: #000;
		}
	}

	/* 关注的按钮 结束 */

	/* 阴影自下而上的样式 开始 */
	.img-box-bg {
		width: 100%;
		height: 100%;
		position: absolute;
		top: 0;
		left: 0;
		z-index: 1;
	}

	.custom.bg-shadeBottom {
		width: 100%;
		position: absolute;
		bottom: 0;
		left: 0;
		z-index: 2;
		background-image: linear-gradient(rgba(0, 0, 0, 0.01), rgba(0, 0, 0, .6));
	}

	.custom.bg-shadeTop {
		width: 100%;
		position: absolute;
		top: 0;
		left: 0;
		z-index: 2;
		background-image: linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.01));
	}

	/* 阴影自下而上 自上而下的样式 结束 */
</style>
